import Vue from 'vue'
const isServer = Vue.prototype.$isServer;

export const on = (function () {
    if (!isServer && document.addEventListener) {
        return function (el, event, fn) {
            if (el && event && fn) {
                el.addEventListener(event, fn, false)
            }
        }
    } else if (!isServer && document.attachEvent) {
        return function (el, event, fn) {
            if (el && event && fn) {
                el.attachEvent('on' + event, fn)
            }
        }
    }
})()

export const off = (function () {
    if (!isServer && document.removeEventListener) {
        return function (el, event, fn) {
            if (el && event) {
                el.removeEventListener(event, fn, false)
            }
        }
    } else if (!isServer && document.detachEvent) {
        return function (el, event, fn) {
            if (el && event) {
                el.detachEvent('on' + event, fn)
            }
        }
    }
})()